/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controlenotas;

import java.awt.Color;
import java.awt.Component;
import java.math.BigDecimal;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author jeferson
 */
public class NotCellRender extends DefaultTableCellRenderer {

    public void setValue(Object value) {
       /* String s = (String) value;
        s = s.replace(",", ".");
        try {
            if(!s.equals("")){
                BigDecimal v = new BigDecimal(s);
                if (v.compareTo(new BigDecimal("5")) >= 0) {
                    setForeground(Color.BLUE);
                } else {
                    setForeground(Color.RED);
                }
            }
        } catch (NumberFormatException ex) {
            System.out.println(ex);
        }*/
        //setBackground(new Color(230, 230, 230));
        setHorizontalAlignment(JLabel.CENTER);
        //outras alterações entram aqui...
        super.setValue(value);
    }

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
            boolean hasFocus, int row, int column) {

        Component c = super.getTableCellRendererComponent(
                table,
                value,
                isSelected,
                hasFocus,
                row,
                column);

        String s = (String) table.getValueAt(row, column);
        s = s.replace(",", ".");
        //altera a aparência do componente baseado no valor da célula (value)
        //String s = (String) value;
        if (!s.equals("")) {
            BigDecimal v = new BigDecimal(s);
            if (v.compareTo(new BigDecimal("5")) >= 0) {
                c.setForeground(Color.BLUE);
            } else {
                c.setForeground(Color.RED);
            }
        } else {
            c.setForeground(Color.BLUE);
        }
        return c;
     }

    
    
}
